#pragma once

#include <string>
#include <fstream>

class Util
{

public:
    static std::string getOneLine(std::string &buf, const std::string &sep)
    {
        // xxxxyyyy z\r\nxxxxy z\r\n
        auto pos = buf.find(sep);
        if ((pos == buf.npos))
            return nullptr;
        std::string line = buf.substr(0, pos);
        // buf.erase(0, line.size() + sep.size()); // 把读到的行擦掉，包括\r\n
        return line;
    }

    static bool readFile(const std::string resource, char *buf, int size)
    {
        // 由于视频、图片等是二进制资源，需要以二进制打开读写，故统一用二进制打开
        std::ifstream ifs(resource, std::ios::binary);
        if (!ifs.is_open())
            return false;

        ifs.read(buf, size);

        // std::string line;
        // while (getline(ifs, line))
        // {
        //     *out += line;
        // }
        ifs.close();
        return true;
    }
};
